package com.cqjtu.education.utils;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @Author: 冉鹏
 * @Date: 2022/4/7 14:17
 */
@Data
@AllArgsConstructor
public class Result {
    /**
     * 状态码
     */
    private int code;

    /**
     * 消息
     */
    private String message;

    /**
     * 原因
     */
    private String reason;

    /**
     * 数据
     */
    private Object data;

    public Result(Object data) {
        this.code = 200;
        this.message = "SUCCESS";
        this.reason = "SUCCESS";
        this.data = data;
    }

    public Result(String reason) {
        this.code = -1;
        this.message = "FAIL";
        this.reason = reason;
    }

    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = "FAIL";
        this.reason = message;
        this.data = data;
    }

    public static Result success(Object data) {
        return new Result(data);
    }

    public static Result fail(String reason) {
        return new Result(reason);
    }

    public static Result fail(int code, String message, Object data) {
        return new Result(code, message, data);
    }
}
